﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing.Design;
namespace Infrastructure.Web.Controls.Mobile
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:MobileImageControl runat=server></{0}:MobileImageControl>")]
    public class MobileImageControl : WebControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]        
        [UrlProperty]
        public string NoColorImageUrl
        {
            get
            {
                String s = (String)ViewState["NoColorImageUrl"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["NoColorImageUrl"] = value;
            }
        }
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]        
        [UrlProperty]
        public string ColorImageUrl
        {
            get
            {
                String s = (String)ViewState["ColorImageUrl"];
                return ((s == null) ? String.Empty : s);
            }
            set
            {
                ViewState["ColorImageUrl"] = value;
            }
        }
        protected override void RenderContents(HtmlTextWriter output)
        {
            if (this.Page.Request.Browser.IsColor)
            {
                output.WriteBeginTag("img");
                output.WriteAttribute("src", this.ResolveUrl(this.ColorImageUrl));
                output.WriteAttribute("width", this.Width.ToString());
                output.WriteAttribute("Height", this.Height.ToString());
                output.WriteEndTag("img");
            }
            else
            {
                output.WriteBeginTag("img");
                output.WriteAttribute("src", this.ResolveUrl(this.NoColorImageUrl));
                output.WriteAttribute("width", this.Width.ToString());
                output.WriteAttribute("Height", this.Height.ToString());
                output.WriteEndTag("img");            
            }
        }
    }
}
